home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- *
- * *** HAPPy P-code Interpriter ***
- *
- * Standard procedure , function の処理
- *
- * void callsp(void)
- * void T_get(int fileno, _store *filebuf, FILE *fp,char *name)
- *
- * Copyright (c) H.Asano 1992.
- **********************************************************************/
-
- #define EXTERN extern
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include "hapai.h"
-
- extern void prerr(int,char*) ;
-
- /********* P-CODE COMPUTER store **********/
- extern _store store[] ;
-
- /********* P-CODE COMPUTER registers **********/
-
- extern int q ; /* q */
-
- extern _store *sp ; /* sp points to top of the stack */
-
- extern int pc ; /* program counter */
- extern int mp ; /* mp points to begginning of a data segment */
- extern int ep ; /* ep points to the maxmum extent of the stack */
- extern int np ; /* np points to top of the dynamically allocated area */
-
-
- extern boolean readlnflag ; /* inputにreadlnをした時 及び
- 起動時には真 */
-
-
- /**************************************************/
- /* searchfile() : fileadrに対応するファイルを探す *
- /**************************************************/
- static int searchfile(int fileno)
- {
- register int i = -1 ;
-
- while(fi[++i].fileadr != fileno) ;
- return(i) ;
- }
-
- /**************************************************/
- /* fileerrmsg() : file関係のエラーメッセージ出力 */
- /**************************************************/
- static void fileerrmsg(int msgno,char *pname,int fileno,char *msg)
- {
- char *fname, *rfname;
- char buf[160] ;
-
- fname = fi[fileno].filename ;
- rfname = fi[fileno].rfname ;
- sprintf(buf,"%s: %s(実ファイル=%s)%s", pname,fname,rfname,msg) ;
- prerr(msgno,buf) ;
- }
-
- /*****************************************/
- /* T_get() : textファイルからの1文字読込 */
- /*****************************************/
- void T_get(int fileno, _store *filebuf, FILE *fp,char *name)
- {
- if(feof(fi[fileno].fp))
- fileerrmsg(42,name,fileno,"がEOFとなっている") ;
-
- (*filebuf).vc = getc(fp) ; /* 1文字先読み */
-
- if(ferror(fp))
- fileerrmsg(181,name,fileno,"で障害が発生した") ;
-
- fi[fileno].eolnflag = (*filebuf).vc == '\n' ;
- /* 改行を読んだ時 真 */
- if(fi[fileno].eolnflag) (*filebuf).vc = ' ' ;
- }
-
- /******************* 各P-codeの処理 ***********************************/
-
- /**************************************/
- /* ATN() : arctan標準関数 */
- /**************************************/
- static void ATN(void)
- {
- (*sp).vr = (float)atan((double)(*sp).vr);
- }
-
- /**************************************/
- /* COS() : cos標準関数 */
- /**************************************/
- static void COS(void)
- {
- (*sp).vr = (float)cos((double)(*sp).vr) ;
- }
-
- /**************************************/
- /* DIS() : dispose標準手続き */
- /**************************************/
- static void DIS(void)
- {
- int ad ;
-
- ad = (*(sp-1)).va ; /* 解放するアドレス */
- if(ad == NilValue)
- prerr(23,"dispose: 引数の値がnilである") ;
- if((np <= ad) && (ad < Maxstore)) { /* 正常値 */
- if(ad == np) np += (short)(*sp).vi ; /* 一番後にnewした時だけ*/
- /* 本当に解放する */
- }
- else prerr(24,"dispose: 引数の値が不定である") ;
- sp-=2 ;
- }
-
- /***************************************/
- /* EOL() : eol標準関数 */
- /***************************************/
- static void EOL(void)
- {
- int fileno ;
-
- fileno = searchfile((*sp).va) ;
-
- if(fi[fileno].mode == undefined)
- fileerrmsg(41,"eoln",fileno,"が不定である") ;
-
- if(feof(fi[fileno].fp))
- fileerrmsg(42,"eoln",fileno,"がEOFとなっている") ;
-
- if((fileno==0) && readlnflag) { /* inputファイルで直前がreadln*/
- T_get(fileno,store+(*sp).va,fi[fileno].fp,"eoln") ;
- /* 次の文字を読込 */
- readlnflag = false ;
- }
- (*sp).vb = fi[fileno].eolnflag ;
- }
-
- /***************************************/
- /* EoF() : eof標準関数 */
- /***************************************/
- static void EoF(void)
- {
- int fileadr ;
- int fileno ;
-
- fileadr = (*sp).va ;
- fileno = searchfile(fileadr) ;
- if((fileno==0) && readlnflag) { /* inputファイルで直前がreadln*/
- T_get(fileno,store+fileadr,fi[fileno].fp,"eof") ;
- /* 次の文字を読込 */
- readlnflag = false ;
- (*sp).vb = feof(fi[fileno].fp) ;
- }
- else { /* 通常のeof */
- if(fi[fileno].mode == undefined)
- fileerrmsg(40,"eof",fileno,"が不定である") ;
-
- (*sp).vb = (fi[fileno].mode == generation) /* 生成モードは真*/
- ? true : feof(fi[fileno].fp) ;
- }
- }
-
- /**************************************/
- /* EXP() : exp標準関数 */
- /**************************************/
- static void EXP(void)
- {
- (*sp).vr = (float)exp((double)(*sp).vr) ;
- }
-
- /**************************************/
- /* GET() : テキストファイル以外のget */
- /**************************************/
- static void GET(void)
- {
- int fileadr ;
- int fileno ;
- FILE *fp ;
-
- fileadr = (*sp--).va ;
- fileno = searchfile(fileadr) ;
- fp = fi[fileno].fp ;
-
- if(fi[fileno].mode != inspection)
- fileerrmsg(14,"get",fileno,"が検査モードでない") ;
-
- if(feof(fp))
- fileerrmsg(16,"get",fileno,"がEOFとなっている") ;
-
- fread(store+fileadr, fi[fileno].filesize*sizeof(_store),1,fp);
-
- if(ferror(fp))
- fileerrmsg(131,"get",fileno,"で障害が発生した") ;
- }
-
- /**************************************/
- /* LOG() : ln標準関数 */
- /**************************************/
- static void LOG(void)
- {
- if((*sp).vr <= (float)0.0)
- prerr(33,"ln: 引数の値が0以下である") ;
- (*sp).vr = (float)log((double)(*sp).vr);
- }
-
- /**************************************/
- /* NEW() : new標準手続き */
- /**************************************/
- static void NEW(void)
- {
- int ad ;
-
- ad = np-(short)(*sp).vi ;
- if(ad <= ep)
- prerr(121,"new: メモリ不足で割り付けができない") ;
- np = ad ;
- ad = (*(sp-1)).va ;
- store[ad].va = np ;
- sp-=2 ;
- }
-
- /**************************************/
- /* PGE() : page標準手続き */
- /**************************************/
- static void PGE(void)
- {
- int fileno ;
-
- fileno = searchfile((*sp--).va) ;
- if(fi[fileno].mode != generation)
- fileerrmsg(9,"page",fileno,"が生成モードでない") ;
-
- if(!fi[fileno].writelnflag) /* 最後が改行でない時 */
- fputc('\n',fi[fileno].fp) ; /* 改行を付ける */
- fputc('\f',fi[fileno].fp) ; /* ホームフィード */
- fi[fileno].writelnflag = false ;
- }
-
- /**************************************/
- /* PUT() : テキストファイル以外のput */
- /**************************************/
- static void PUT(void)
- {
- int fileadr ;
- int fileno ;
- FILE *fp ;
-
- fileadr = (*sp--).va ;
- fileno = searchfile(fileadr) ;
- fp = fi[fileno].fp ;
-
- if(fi[fileno].mode != generation)
- fileerrmsg(9,"put",fileno,"が生成モードでない") ;
-
- fwrite(store+fileadr, fi[fileno].filesize*sizeof(_store),1,fp) ;
-
- if(ferror(fp))
- fileerrmsg(182,"put",fileno,"で障害が発生した") ;
- }
-
- /**************************************/
- /* RLN() : テキストファイルのreadln */
- /**************************************/
- static void RLN(void)
- {
- FILE *fp ;
- _store *filebuf ;
- int fileno ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
- filebuf = fi[fileno].filebuf ;
-
- if(fi[fileno].mode != inspection)
- fileerrmsg(14,"read",fileno,"が検査モードでない") ;
-
- if((fileno==0) && readlnflag)
- T_get(fileno,filebuf,fp,"readln");
-
- while(!fi[fileno].eolnflag)
- T_get(fileno,filebuf,fp,"readln"); /* 改行文字を読み飛ばす */
- if(fileno == 0) readlnflag = true ;
- else
- T_get(fileno,filebuf,fp,"readln") ; /* 次の文字を読込 */
-
- sp-- ;
- }
-
- /*****************************************/
- /* RDC() : テキストファイルからの文字読込*/
- /*****************************************/
- static void RDC(void)
- {
- FILE *fp ;
- _store *filebuf ;
- int fileno ;
- short ad ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
- filebuf = fi[fileno].filebuf ;
-
- if(fi[fileno].mode != inspection)
- fileerrmsg(14,"read",fileno,"が検査モードでない") ;
-
- if(feof(fp))
- fileerrmsg(16,"read",fileno,"がEOFとなっている") ;
-
- if((fileno==0) && readlnflag) { /* inputファイルで直前がreadln*/
- T_get(fileno,filebuf,fp,"read") ; /* 次の文字を読込 */
- readlnflag = false ;
- }
-
- ad = (*(sp-1)).va ;
- store[ad].vc = (*filebuf).vc ; /* バッファ変数から変数へ代入 */
-
- T_get(fileno,filebuf,fp,"read") ; /* 次の文字を読込 */
-
- sp-=2 ;
- }
-
- /*****************************************/
- /* RDI() : テキストファイルからの整数読込*/
- /*****************************************/
- static void RDI(void)
- {
- FILE *fp ;
- _store *filebuf ;
- int fileno ;
- int ad ;
- int lch ;
- integer ival = 0 ;
- int sign = 1 ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
- filebuf = fi[fileno].filebuf ;
- ad = (*(sp-1)).va;
-
- if(fi[fileno].mode != inspection)
- fileerrmsg(14,"read",fileno,"が検査モードでない") ;
-
- if((fileno==0) && readlnflag) { /* inputファイルで直前がreadln*/
- T_get(fileno,filebuf,fp,"read") ; /* 次の文字を読込 */
- readlnflag = false ;
- }
-
- while((*filebuf).vc == ' ') /* 空白読み飛ばし */
- T_get(fileno,filebuf,fp,"read");
- if(((*filebuf).vc=='+') || ((*filebuf).vc=='-')) { /* 符号の時 */
- sign = ((*filebuf).vc=='+') ? 1 : -1 ; /* 符号に応じた正負 */
- T_get(fileno,filebuf,fp,"read");
- }
-
- if(((*filebuf).vc >= '0') && ((*filebuf).vc <= '9')) { /* 数字 */
- do {
- lch = (*filebuf).vc - '0' ;
- if(ival <= (Maxint-lch/10)) /* 上限チェック */
- ival = ival*10 + lch ;
- else
- fileerrmsg(54,"read",fileno,
- "から符号付き整数の形式でないものを読もうとした") ;
- T_get(fileno,filebuf,fp,"read");
- if(feof(fp)) break ; /* eofだったら終わり */
- } while(('0' <= (*filebuf).vc ) && ((*filebuf).vc <= '9')) ;
-
- store[ad].vi = sign * ival ;
- }
- else { /* 最初に数字がこなかった時 */
- if(feof(fp)) fileerrmsg(16,"read",fileno,"がEOFとなっている") ;
- fileerrmsg(54,"read",fileno,
- "から符号付き整数の形式でないものを読もうとした") ;
- }
-
- sp-=2;
- }
-
- /*****************************************/
- /* RDR() : テキストファイルからの実数読込*/
- /*****************************************/
- static void RDR(void)
- {
- FILE *fp ;
- _store *filebuf ;
- int fileno ;
- char buf[80] ;
- char *stopstring ;
- int i ;
- integer ival = 0 ; /* 整数部の値 */
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
- filebuf = fi[fileno].filebuf ;
-
- if(fi[fileno].mode != inspection)
- fileerrmsg(14,"read",fileno,"が検査モードでない") ;
-
- if((fileno==0) && readlnflag) { /* inputファイルで直前がreadln*/
- T_get(fileno,filebuf,fp,"read") ; /* 次の文字を読込 */
- readlnflag = false ;
- }
-
- for(i=0;i<80;i++) *(buf+i) = '\0'; /* バッファクリア */
- i = 0 ;
-
- while((*filebuf).vc == ' ') /* 空白読み飛ばし */
- T_get(fileno,filebuf,fp,"read");
- if(((*filebuf).vc=='+') || ((*filebuf).vc=='-')) { /* 符号の時 */
- buf[i++] = (char)(*filebuf).vc ;
- T_get(fileno,filebuf,fp,"read");
- }
-
- if(((*filebuf).vc >= '0') && ((*filebuf).vc <= '9')) { /* 数字 */
- do {
- buf[i++] = (char)(*filebuf).vc ;
- ival = ival*10 + (*filebuf).vc - '0';
- T_get(fileno,filebuf,fp,"read");
- if(feof(fp)) break ; /* eofだったら終わり */
- } while(('0' <= (*filebuf).vc ) && ((*filebuf).vc <= '9')) ;
-
- if((*filebuf).vc == '.') { /* 小数点 */
- buf[i++] = (char)(*filebuf).vc ;
- T_get(fileno,filebuf,fp,"read"); /* 小数点を読み飛ばす */
- if(((*filebuf).vc >= '0') && ((*filebuf).vc <= '9')) { /* 数字 */
- do {
- buf[i++] = (char)(*filebuf).vc ;
- T_get(fileno,filebuf,fp,"read");
- if(feof(fp)) break ; /* eofだったら終わり */
- } while(('0' <= (*filebuf).vc ) && ((*filebuf).vc <= '9')) ;
- }
- else goto error ; /* . の次が数字でない時 */
- }
-
- if(((*filebuf).vc == 'e') || ((*filebuf).vc == 'E')) { /* 指数*/
- buf[i++] = (char)(*filebuf).vc ;
- T_get(fileno,filebuf,fp,"read"); /* eまたはEを読み飛ばす */
- if(((*filebuf).vc=='+') || ((*filebuf).vc=='-')) { /* 符号の時*/
- buf[i++] = (char)(*filebuf).vc ;
- T_get(fileno,filebuf,fp,"read");
- }
- if(((*filebuf).vc >= '0') && ((*filebuf).vc <= '9')) { /* 数字*/
- do {
- buf[i++] = (char)(*filebuf).vc ;
- T_get(fileno,filebuf,fp,"read");
- if(feof(fp)) break ; /* eofだったら終わり */
- } while(('0' <= (*filebuf).vc ) && ((*filebuf).vc <= '9')) ;
- }
- else goto error ; /* 指数部の最初が数字でない */
- }
- }
- else goto error ; /* 最初に数字がこなかった時 */
-
- store[(*(sp-1)).va].vr = (float)strtod(buf,&stopstring) ;
-
- sp -= 2;
- return ;
-
- error : /* 符号つき数字でない時 */
- if(feof(fp)) fileerrmsg(16,"read",fileno,"がEOFとなっている") ;
- fileerrmsg(56,"read",fileno,
- "から符号付き数の形式でないものを読もうとした") ;
- }
-
- /****************************************/
- /* RST() : テキストファイル以外のreset */
- /****************************************/
- static void RST(void)
- {
- int fileadr ;
- int fileno ;
- FILE *fp ;
-
- fileadr = (*sp--).va ;
- fileno = searchfile(fileadr) ;
-
- fclose(fi[fileno].fp) ; /*まずクローズ(エラーでも良い)*/
- fp = fopen(fi[fileno].rfname,"rb") ;
- if(fp == NULL)
- fileerrmsg(13,"reset",fileno,"が不定である") ;
-
- fi[fileno].mode = inspection ; /* 検査モード */
- fi[fileno].fp = fp ;
- fread(store+fileadr, fi[fileno].filesize*sizeof(_store),1,fp) ;
- /* 最初の要素をバッファ変数に */
- }
-
- /******************************************/
- /* RWT() : テキストファイル以外のrewrite */
- /******************************************/
- static void RWT(void)
- {
- int fileno ;
-
- fileno = searchfile((*sp--).va) ;
-
- fclose(fi[fileno].fp) ; /*まずクローズ(エラーでも良い)*/
- fi[fileno].fp = fopen(fi[fileno].rfname,"wb") ;
- if(fi[fileno].fp == NULL)
- fileerrmsg(132,"rewrite",fileno,"のオープンができない") ;
-
- fi[fileno].mode = generation ; /* 生成モード */
- }
-
- /***************************************/
- /* SIN() : sin標準関数 */
- /***************************************/
- static void SIN(void)
- {
- (*sp).vr = (float)sin((double)(*sp).vr) ;
- }
-
- /***************************************/
- /* SQT() : sqrt標準関数 */
- /***************************************/
- static void SQT(void)
- {
- if((*sp).vr < (float)0.0) /* 負の平方根 */
- prerr(34,"sqrt:引数の値が負である") ;
- (*sp).vr = (float)sqrt((double)(*sp).vr);
- }
-
- /***************************************/
- /* TGT() : テキストファイルのget */
- /***************************************/
- static void TGT(void)
- {
- FILE *fp ;
- _store *filebuf ;
- int fileno ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
- filebuf = fi[fileno].filebuf ;
-
- if(fi[fileno].mode != inspection)
- fileerrmsg(14,"get",fileno,"が検査モードでない") ;
-
- if((fileno==0) && readlnflag) { /* inputファイルで直前がreadln*/
- T_get(fileno,filebuf,fp,"get") ; /* 次の文字を読込 */
- readlnflag = false ;
- }
-
- if(feof(fp))
- fileerrmsg(16,"get",fileno,"がEOFとなっている") ;
-
- T_get(fileno,filebuf,fp,"get") ; /* 次の文字を読込 */
-
- sp-- ;
- }
-
- /***************************************/
- /* TPT() : テキストファイルへのput */
- /***************************************/
- static void TPT(void)
- {
- FILE *fp ;
- int fileno ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
- if(fi[fileno].mode != generation)
- fileerrmsg(9,"put",fileno,"が生成モードでない") ;
-
- if(fputc((*(store+(*sp--).va)).vc,fp) == EOF) /* 文字出力 */
- fileerrmsg(131,"put",fileno,"で障害が発生した") ;
- fi[fileno].writelnflag = false ;
- }
-
- /***************************************/
- /* TRS() : テキストファイルへのreset */
- /***************************************/
- static void TRS(void)
- {
- FILE *fp ;
- int fileno ;
- _store *filebuf ;
-
- fileno = searchfile((*sp--).va) ;
- filebuf = fi[fileno].filebuf ;
-
- if((strcmp(fi[fileno].filename,"input")==0) || /* inputファイル */
- (strcmp(fi[fileno].filename,"output")==0)) /* outputファイル */
- fileerrmsg(81,"reset",fileno,"に対してresetはできない") ;
-
- if(fi[fileno].mode == generation) /* 今が生成モードの時 */
- if(! fi[fileno].writelnflag) /* 最後が改行マークでない時 */
- fputc('\n',fi[fileno].fp) ; /* 改行を書き込む */
- fclose(fi[fileno].fp) ; /* ファイルクローズ */
- fp = fopen(fi[fileno].rfname,"rt") ; /* テキストモードオープン */
- if(fp == NULL)
- fileerrmsg(13,"reset",fileno,"が不定である") ;
- fi[fileno].fp = fp ;
- fi[fileno].mode = inspection ; /* 検査モード */
- fi[fileno].textfile = true ; /* テキストファイル */
-
- T_get(fileno,filebuf,fp,"reset") ; /* 最初の文字を読む */
- }
-
- /***************************************/
- /* TRW() : テキストファイルへのrewrite */
- /***************************************/
- static void TRW(void)
- {
- int fileno ;
-
- fileno = searchfile((*sp--).va) ;
-
- if((strcmp(fi[fileno].filename,"input")==0) || /* inputファイル */
- (strcmp(fi[fileno].filename,"output")==0)) /* outputファイル */
- fileerrmsg(82,"rewrite",fileno,"に対してrewriteはできない") ;
-
- fclose(fi[fileno].fp) ; /*まずクローズ(エラーでも良い)*/
- fi[fileno].fp = fopen(fi[fileno].rfname,"wt") ;
- if(fi[fileno].fp == NULL)
- fileerrmsg(132,"rewrite",fileno,"のオープンができない") ;
-
- fi[fileno].mode = generation ; /* 生成モード */
- fi[fileno].textfile = true ; /* テキストファイル */
- fi[fileno].writelnflag = true; /* rewrite直後には改行いらない*/
- }
-
- /***************************************/
- /* WLN() : writeln標準手続き */
- /***************************************/
- static void WLN(void)
- {
- int fileno ;
-
- fileno = searchfile((*sp--).va) ;
- if(fi[fileno].mode != generation)
- fileerrmsg(9,"writeln",fileno,"が生成モードでない") ;
- fputc('\n',fi[fileno].fp) ;
- fi[fileno].writelnflag = true ;
- }
-
- /***************************************/
- /* WRB() : boolean型の出力 */
- /***************************************/
- static void WRB(void)
- {
- int fileno ;
- char *put ;
- short i,j,k ;
- FILE *fp ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
-
- if(fi[fileno].mode != generation)
- fileerrmsg(9,"write",fileno,"が生成モードでない") ;
-
- put = ((*(sp-2)).vb) ? "TRUE" : "FALSE" ;
- j = strlen(put) ; /* 出力文字長 */
- k = (short)(*(sp-1)).vi ; /* 出力幅 */
-
- if(k>j) /* 空白をつける必要のある時 */
- for(i=1;i<=(k-j);i++) fputc(' ',fp) ;
- else j= k ;
- for(i=0;i<j;i++) fputc((int)put[i], fp);
-
- fi[fileno].writelnflag = false ;
-
- sp-=3;
- }
-
- /***************************************/
- /* WRC() : テキストファイルに文字出力 */
- /***************************************/
- static void WRC(void)
- {
- int fileno ;
- int i ;
- FILE *fp ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
-
- if(fi[fileno].mode != generation)
- fileerrmsg(9,"write",fileno,"が生成モードでない") ;
-
- for(i=1;i<(int)(*(sp-1)).vi;i++) fputc(' ',fp) ;
- fputc((*(sp-2)).vc,fp) ;
-
- fi[fileno].writelnflag = false ;
-
- sp-=3 ;
- }
-
- /***************************************/
- /* WRF() : テキストファイルに実数出力 */
- /***************************************/
- static void WRF(void)
- {
- int fileno ;
- FILE *fp ;
- char buf1[80] ;
- char buf2[80] ;
- int width ;
- int i ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
-
- if(fi[fileno].mode != generation)
- fileerrmsg(9,"write",fileno,"が生成モードでない") ;
-
- *buf1 = '%' ; /* %1.xfという形を生成 */
- sprintf(buf1+1,"1.%df",(int)(*(sp-1)).vi) ; /* 少数点以下の桁数*/
- width = sprintf(buf2,buf1,(*(sp-3)).vr); /* 固定小数点変換 */
- for(i=width;i<(int)(*(sp-2)).vi;i++)
- fputc(' ',fp) ; /* 前に空白を出力する */
- fputs(buf2,fp) ;
-
- fi[fileno].writelnflag = false ;
-
- sp-=4 ;
- }
-
- /***************************************/
- /* WRI() : テキストファイルに整数出力 */
- /***************************************/
- static void WRI(void)
- {
- char buf[12];
- int fileno ;
- FILE *fp ;
- short i,len ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
-
- if(fi[fileno].mode != generation)
- fileerrmsg(9,"write",fileno,"が生成モードでない") ;
-
- len=sprintf(buf,"%ld",(*(sp-2)).vi); /* 数字出力に必要な桁 */
- for(i=(short)(*(sp-1)).vi;i>len;i--)
- fputc(' ',fp) ; /* 数字の前に空白を出力する */
- fputs(buf,fp) ;
-
- fi[fileno].writelnflag = false ;
-
- sp -= 3 ;
- }
-
- /***************************************/
- /* WRR() : テキストファイルに実数出力 */
- /***************************************/
- static void WRR(void)
- {
- char buf[15] ;
- int keta ;
- int width ;
- int point ;
- int fileno ;
- FILE *fp ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
-
- if(fi[fileno].mode != generation)
- fileerrmsg(9,"write",fileno,"が生成モードでない") ;
-
- keta = (int)(*(sp-1)).vi ; /* 出力桁 */
- width = (keta >= 9) ? keta : 9 ; /* 必要出力桁 */
- point = width - 8 ;
- *buf = '%' ; /* %x.xEの形に変換 */
- sprintf(buf+1,"%d.%dE",width,point);
- fprintf(fp,buf,(*(sp-2)).vr) ;
-
- fi[fileno].writelnflag = false ;
-
- sp -= 3 ;
- }
-
- /***************************************/
- /* WRS() : テキストファイルに文字列出力*/
- /***************************************/
- static void WRS(void)
- {
- int fileno ;
- FILE *fp ;
- short i,j,k ;
- int ad ;
-
- fileno = searchfile((*sp).va) ;
- fp = fi[fileno].fp ;
-
- if(fi[fileno].mode != generation)
- fileerrmsg(9,"write",fileno,"が生成モードでない") ;
-
- ad= (*(sp-3)).va ;
- k = (short)(*(sp-2)).vi ; /* k=出力幅 */
- j = (short)(*(sp-1)).vi ; /* j=文字数 */
-
- if(k>j) /* 空白をつける必要のある時 */
- for(i=1;i<=(k-j);i++) fputc(' ',fp) ;
- else j= k ;
- for(i=0;i<j;i++)
- fputc(store[ad+i].vc,fp);
-
- fi[fileno].writelnflag = false ;
-
- sp-=4;
- }
-
-
- /**********************************************************************/
- /* P-code 別 処理エントリ表 */
- /**********************************************************************/
-
- static struct entry {
- void (*func)(void) ;
- } pcd[] = {
- /* xx0 xx1 xx2 xx3 xx4 xx5 xx6 xx7 xx8 xx9 */
-
- /*00x*/ GET, PUT, RST, RLN, NEW, WLN, WRS, WRB, WRI, WRR,
- /*01x*/ WRC, RDI, RDR, RDC, SIN, COS, EXP, LOG, SQT, ATN,
- /*02x*/ PGE, EoF, EOL, DIS, WRF, RWT, TRS, TRW, TGT, TPT
- };
-
- /********* callsp() : csp 命令の実行 ***********/
- void callsp(void)
- {
- pcd[q].func() ; /* opに対応した命令を実行 */
- }